﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DDD.Core;

using FloatComparer = DDDTest.Helper.FloatComparer;

namespace DDDTest.Core {
    [TestClass]
    public class TestCache {

        /// <summary>
        /// 
        /// </summary>
        [TestMethod]
        public void Test_New1 () {
            var obj = new Node ();
            var res = new Cache<int> (obj, 100);

            Assert.AreEqual (true, res.IsValid);
            Assert.AreEqual (obj, res.Object);
            Assert.AreEqual (100, res.Value);
            Assert.AreEqual (typeof (Node), res.ObjectType);
        }

        /// <summary>
        /// GCによって回収されたオブジェクトのリソース参照が
        /// Invalidになるのを確認するテスト
        /// </summary>
        [TestMethod]
        public void Test_Invalidate () {
            var obj = new Node ();
            var res = new Cache<int> (obj, 100);

            obj = null;
            System.GC.Collect ();

            Assert.AreEqual (false, res.IsValid);
            Assert.AreEqual (null, res.Object);
            Assert.AreEqual (100, res.Value);
            Assert.AreEqual (typeof (Node), res.ObjectType);
        }
    }
}
